package com.jthinker.service.impl;

import com.jthinker.bean.vo.QueryResult;
import com.jthinker.bean.vo.SearchFilter;
import com.jthinker.dao.ResourceDao;
import com.jthinker.service.ResourceService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * Created by chen.gang on 15-2-16.
 */
@Service
public class ResourceServiceImpl implements ResourceService
{
    private static final Logger LOGGER = LoggerFactory.getLogger(ResourceService.class);

    @Resource
    private ResourceDao resourceDao;

    @Override
    public Map<String, Object> findOne(Long resourceId)
    {
        return resourceDao.findOne(resourceId);
    }

    @Override
    public List<Map<String, Object>> findAll()
    {
        return resourceDao.findAll();
    }

    @Override
    public QueryResult<Map<String, Object>> query(SearchFilter filter)
    {
        return resourceDao.query(filter);
    }

    @Override
    public void create(Map<String, Object> record) throws Exception
    {
        try
        {
            resourceDao.create(record);
        }
        catch (Exception e)
        {
            LOGGER.error("Exception: {}", e);
            throw e;
        }
    }
}
